/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package wifipositioner;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;

/**
 *
 * @author Fuglsang
 */
public class ScoreNN {

    private ArrayList<ResultItem> listError = new ArrayList<>();
    private double interval = 1.0;

    public ArrayList<ResultItem> CalculateError(Collection<PositionCalculationResult> results) {

        double errorComuleret = 0.0;

        for (PositionCalculationResult positionCalculationResult : results) {
            errorComuleret = Math.sqrt(Math.pow(positionCalculationResult.getReal().getX() - positionCalculationResult.getEstimated().getX(), 2) + Math.pow(positionCalculationResult.getReal().getY() - positionCalculationResult.getEstimated().getY(), 2));
            //System.out.println("error " + errorComuleret);
            ResultItem resultItem = new ResultItem();
            resultItem.setErrorDist(errorComuleret);

            listError.add(resultItem);
        }

        errorDistribution();

        return listError;
    }

    public void errorDistribution() {

        for (ResultItem r : listError) {
            int numberOfItemsSmallerThan = 0;  
            for (ResultItem re : listError) {
                if(re.getErrorDist() <= r.getErrorDist()) {
                    numberOfItemsSmallerThan += 1; 
                }
            }
            
            System.out.println("ResultItem " + r.getErrorDist() + " numberOfItemsSmallerThan " + numberOfItemsSmallerThan);
            float errorPect = (float) ((100.0/listError.size())*numberOfItemsSmallerThan); 
            System.out.println("errorPect "+ errorPect);
            r.setErrorProcentage(errorPect);            
        }
        
        System.out.println("listError.size() " + listError.size());

    }
}
